<html lang="zh-CN">

<head>

<meta charset="utf-8">

<title>轻应用演示</title>

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<script type="text/javascript" src="jQuery/jquery-2.2.3.min.js"></script>

</head>

<body>

<button onclick="gettoken()">获得token</button>

<button onclick="getcontext()">获得context</button>

<h3>获得的access_token</h3>

<div id='tk'>   </div>

<h3>获得的上下文</h3>

<div id='ct'>   </div>

<script type="text/javascript">

var ticket=getUrlParam('ticket'),token;

function gettoken(){
	
	alert(ticket);

$.ajax({

type: "GET",

dataType:"JSONP",

url:"http://do.yunzhijia.com/openauth2/api/appAuth2",

data:{

'grant_type':'client_credential',

'appid':'375397601',

'secret':'123'

},

headers:{

'Access-Control-Allow-Origin':'*'

}    }).done(function(ok) {

$('#tk').html(JSON.stringify(ok))

token=ok.access_token

}).fail(function(a) {

alert(a.responseText)

})}

function getcontext(){

$.ajax({

type: "GET",

dataType:"JSONP",

data:{

ticket:ticket,

"access_token":token

},

url: "http://yunxt.kingdee.com/openauth2/api/getcontext"

}).done(function(ok) {

$('#ct').html('用户:'+ok.username+',企业:'+ok.eid)

$('#ct').html(JSON.stringify(ok))

}).fail(function(a) {

alert(a.responseText)

})}

//获取url中的参数

function getUrlParam(name) {
	
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象

var r = window.location.search.substr(1).match(reg);  //匹配目标参数


if (r != null){ 
	return unescape(r[2]);
}
return null; //返回参数值

}

</script>

</body>
